package cn.com.dhcc.app.pub.core.job.filedata;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.base.IocBean;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.core.util.Status;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.app.pub.core.consts.NodeInfoParam;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.service.exch.filedata.FileDataExchageLifecycle;
import cn.com.dhcc.turbo.service.registry.BaseInfoService;

/**
 * 读取数据库未发送列表等。发送到目的服务器
 */

public class FileDataRemoteStoreCronJob extends StatefulMethodInvokingJob {
	private Logger logger = Log.getLogger(LOGTYPE.QUARTZJOB);
	
//	private static Object obj = new Object();
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
//		synchronized (obj) {
			BaseInfoService baseInfoService=(BaseInfoService) CM.getBeanByName(IocBean.BASE_INFO_SERVICEIMPL_BEAN);
			NodeInfo localNode;
			try {
				logger.info("["+AppConst.installIp+"]"+"定时任务FileDataRemoteStoreCronJob开始执行....");
				localNode = baseInfoService.getCurrentNodeInfo();
				 if (localNode!=null) {//节点初始化后才开始定时任务
					 FileDataExchageLifecycle service = (FileDataExchageLifecycle) CM.getBeanByName("fileDataExchageLifecycle");
						service.remoteStore();
						logger.info("定时任务FileDataRemoteStoreCronJob网闸节点存储条件"+( !NodeInfoParam.isInnerNode() && AppConst.YES.equals(localNode.getHasGap())));
						if (!NodeInfoParam.isInnerNode() && AppConst.YES.equals(localNode.getHasGap())) {//如果是内网，并且有网闸
							 Status status=service.outerEntrepotStore();
							 logger.info("outerEntrepotStore的返回结果"+status);
						}
						
				 }
				 logger.info("["+AppConst.installIp+"]"+"定时任务FileDataRemoteStoreCronJob执行结束....");
			} catch (ServiceException e) {
				logger.error("["+AppConst.installIp+"]"+"定时任务FileDataSendLocalRespCronJob执行时出错:"+e);
			}
//		}
	}
}